package com.hqyj.project.controller;

import com.hqyj.project.entity.Leave;
import com.hqyj.project.entity.User;
import com.hqyj.project.service.AttendanceService;
import com.hqyj.project.service.UserService;
import com.hqyj.project.utils.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/attendance")
@ResponseBody
public class AttendanceController {
    @Autowired
    private AttendanceService attendanceService;

    // 打卡
    @PostMapping("/clockIn")
    @ResponseBody
    public CommonResult clockIn(HttpServletRequest request){
        User user = (User) request.getSession().getAttribute("u");
        Integer userId = user.getUserId();
        return attendanceService.clockIn(userId);
    }

    // 考勤情况查询
    @GetMapping("/record")
    @ResponseBody

    public CommonResult queryClockInUser(HttpServletRequest request){
        User user = (User) request.getSession().getAttribute("u");
        Integer userId = user.getUserId();
        return attendanceService.queryAttendUser(userId);
    }

    // 查询请假的员工
    @GetMapping("/myLeave")
    @ResponseBody
    public CommonResult queryLeave(HttpServletRequest request){
        User user = (User) request.getSession().getAttribute("u");
        Integer userId = user.getUserId();
        Leave leave = new Leave();
        leave.setUserId(userId);
        return attendanceService.queryLeave(leave);
    }

    @GetMapping("/early")
    @ResponseBody
    public CommonResult querySettingEarly(){
        return attendanceService.querySettingEarly();
    }

    @GetMapping("/late")
    @ResponseBody
    public CommonResult querySettingLate(){
        return attendanceService.querySettingLate();
    }

    @GetMapping("/leave")
    @ResponseBody
    public CommonResult querySettingLeave(){
        return attendanceService.querySettingLeave();
    }

    @GetMapping("/report")
    @ResponseBody
    public CommonResult report(){
        return attendanceService.report();
    }
}
